<?php

namespace Home\Controller;

use Home\Core\CommandSDK;

class AccountOverviewController extends BaseController
{

    /**
     * 检索人员列表
     */
    public function account_overview()
    {
        $cookie = base64_decode($_COOKIE['user_info']);   // 解析cookie
        parse_str($cookie,$userinfo);
        $title = '企业用户详情';
        if($userinfo['userrole'] == '2'){   // 区域管理员传参数
            $param['areaid']=$_SESSION['AreaId'];
            $title = '区域用户详情';
        }
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::AccountOverview, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $totaluser = '';
        $newuser = '';
        $date = '';
        $tmp_user = [];
        foreach ($array['oneweeknewuser'] as $key=>$value){
            array_push($tmp_user,$value['totaluser']);
            $totaluser .= $value['totaluser'].',';
            $newuser .= $value['newuser'].',';
            $date .= "'".date("Y-m-d",$value['date'])."',";
        }
        $totaluser = '['.rtrim($totaluser,',').']';
        $newuser = '['.rtrim($newuser,',').']';
        $date = '['.rtrim($date,',').']';
        $this->assign('userinfo', $userinfo);
        $this->assign('newuser', $newuser);
        $this->assign('date', $date);
        $this->assign('totaluser', $totaluser);
        $this->assign('array', $array);
        $this->assign('title', $title);
        $this->assign('areaname', $_SESSION['AreaName']);
        $this->assign('max',max($tmp_user)*2);
        $this->display();
    }

    /**
     * 修改企业联系人
     */
    public function ModifyContact_post()
    {
        $param = I('post.');
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::ModifyContact, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        if($return->result == '0'){   // 编辑成功，更新cookie数据
            $cookie = base64_decode($_COOKIE['user_info']);   // 解析cookie
            parse_str($cookie,$userinfo);
            $userinfo['contact'] = $param['username'];
            $userinfo['tel'] = $param['tel'];
            setcookie("user_info", base64_encode(http_build_query($userinfo)),0,'/');
        }
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }
  


}